package com.alan.product.issue.controller;

import com.alan.product.issue.entity.Player;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;

@RestController
public class BusinessController {

    private volatile boolean flag;

    private static Map<Long, Player> map = new ConcurrentHashMap<>();

    @PostMapping("login")
    public String login() {
        Long id = ThreadLocalRandom.current().nextLong();
        map.put(id, new Player(id));
        return "success";
    }

    @PostMapping("logout")
    public String logout() {
        // do something
        return "success";
    }

    @GetMapping("get")
    public String get() throws InterruptedException {
        while (!flag) {
//            Thread.sleep(1);
        }
        return "success";
    }

    @PostMapping("updateFlag")
    public String updateFlag() {
        this.flag = !flag;
        return "success";
    }
}
